<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');?>
<div class="middle padtop10 myclear">
	<div class="page-content">
		
		<!-- bread crumb -->
		<p id="bread-crumb">
			<a href="<?php echo base_url();?>">
				<?php echo $lang['home']?>
			</a>
			<a href="<?php echo site_url('budget');?>">
				<?php echo $lang['financial']?>
			</a>
			<?php echo $groupname;?>
		</p><!-- end bread crumb -->
		
		<h3>
			<?php echo $lang['agency'].': '.$groupname;?>
		</h3>
		<br style="clear:both;" />
		<table cellpadding="3" cellspacing="1" width="100%">
		<tr>
			<td style="padding:5px 5px">
				<?php echo $lang['sys_money_total'].': '.number_format($summary->ad);?> VND
			</td>
			<td style="padding:5px 5px">
				<?php echo $lang['sys_money_use'].': '.number_format($summary->sub);?> VND
			</td>
			<td style="padding:5px 5px">
				<?php echo $lang['sys_promotion'].': '.number_format($summary->promotion)?> VND
			</td>
		</tr>
		</table>
		<br />
		<table cellpadding="3" cellspacing="1">
			<tr>
				<td>
					<b class="ver-middle marright5"><?php echo $lang['theo']?>: </b>
					<select id="typetime" class="ver-middle">
						<?php foreach ($lang['ar_typetime'] as $key	=>	$value){?>
						<option value="<?php echo $key;?>" <?php echo ($key == $typetime ? 'selected="selected"' : '');?>><?php echo $value;?></option>
						<?php }?>
					</select>
				</td>
				<td style="padding-left:15px">
					<b class="ver-middle marright5"><?php echo $lang['agency']?>: </b>
					<select id="slGroup" class="ver-middle">
						<!-- <option value="0" <?php echo ($groupid == 0 ? 'selected="selected"' : '');?>><?php echo $lang['default']?></option> -->
						<?php foreach ($groups as $item){?>
						<option value="<?php echo $item['groupid']?>" <?php echo ($item['groupid'] == $groupid ? 'selected="selected"' : '');?>><?php echo $item['groupname']?></option>
						<?php }?>
					</select>
				</td>
                <td style="padding-left:15px">
					<b class="ver-middle marright5"><?php echo $lang['user']?>: </b>
					<input type="text" id="txtUser" size="20" value="<?php echo $usr;?>" />
				</td>
				<td style="padding-left:15px">
					<b class="ver-middle marright5"><?php echo $lang['date']?>: </b>
					<input type="text" id="slDate" size="30" value="<?php echo $startdate.' / '.$enddate;?>" />
				</td>
				<td style="padding-left:15px">
					<input type="button" value="<?php echo $lang['apply'];?>" onclick="filterChange();" />
				</td>
			</tr>
		</table><br />
		<table class="tbl-list" width="100%" border="1">
			<tr>
				<td width="5%" class="td-label" style="text-align:center">
					<b>#</b>
				</td>
				<td width="30%" class="td-label">
					<b><?php echo $lang['name']?></b>
				</td>
				<td class="td-label">
					<b><?php echo $lang['date']?></b>
				</td>
				<td class="td-label" style="text-align:right">
					<b><?php echo $lang['money_ad']?> (VND)</b>
				</td>
				<td class="td-label" style="text-align:right">
					<b><?php echo $lang['money_sub']?> (VND)</b>
				</td>
				<td class="td-label" style="text-align:right">
					<b><?php echo $lang['money_promotion']?> (VND)</b>
				</td>
			</tr>
			<?php $i = 0; foreach ($items as $item){ $i++; ?>
			<tr>
				<td style="text-align:center">
					<?php echo $i;?>
				</td>
				<td>
					<a href="<?php echo site_url('budget/user/?u='.$item->username.'&uid='.$item->id.'&gid='.$groupid.'&fd='.$startdate.'&td='.$enddate);?>">
						<?php echo $item->username;?>
					</a>
				</td>
				<td>
					<?php echo $item->time;?>
				</td>
				<td style="text-align:right">
					<?php echo number_format($item->ad);?>
				</td>
				<td style="text-align:right">
					<?php echo number_format($item->sub);?>
				</td>
				<td style="text-align:right">
					<?php echo number_format($item->promotion);?>
				</td>
			</tr>
			<?php }?>
			<tr>
				<td colspan="3" class="td-label" style="text-align:right">
					<b><?php echo $lang['sum'];?>:</b>
				</td>
				<td class="td-label" style="text-align:right">
					<b><?php echo number_format($summary->ad);?></b>
				</td>
				<td class="td-label" style="text-align:right">
					<b><?php echo number_format($summary->sub);?></b>
				</td>
				<td class="td-label" style="text-align:right">
					<b><?php echo number_format($summary->promotion);?></b>
				</td>
			</tr>
		</table>
		<!-- paging -->
			<div class="myclear martop20">
				<div class="brv-paging-left">
					<table class="tbl-list brv-paging" border="1">
						<tr>
							<td class="brv-paging-name">
								<?php echo $lang['page'].' '. $page.' ['.$pages.']'?>
							</td>
							
							<td class="brv-paging-pre-next">
								<img class="brv-img-pre" alt="previous" src="/images/imgpre.gif" onclick="goPage(<?php echo $page > 1 ? $page - 1 : $page;?>)" />
								<img class="brv-img-next" alt="next" src="/images/imgnext.gif" onclick="goPage(<?php echo $page < $pages ? $page + 1 : $page;?>)" />
							</td>
							<td class="brv-paging-pre-next">
								<select name="lstLimit" id="lstLimit" onchange="filterChange();">
									<?php $option = array(20, 50, 100, -1); foreach ($option as $item){?>
									<option value="<?php echo $item;?>" <?php if($limit == $item) echo 'selected="selected"';?>>
										<?php echo $item == -1 ? 'All' : $item;?>
									</option>
									<?php }?>
								</select>&nbsp; <?php echo $lang['items_in_page'];?>
							</td>
						</tr>
					</table>
				</div>
				<!-- important. fix for ie 6. Don't remove -->
				<!--[if IE 6]><br class="clearboth" /><![endif]-->
			</div>
			<!-- end paging -->
	</div>
</div><br />
<script type="text/javascript">
function goPage(strVal)
{
	var limit = $('#lstLimit').val();
	window.location = '<?php echo site_url('budget/agency/?gid='.$groupid.'&type='.$typetime.'&fd='.$startdate.'&td='.$enddate);?>&limit='+limit+'&page=' + strVal;
}
function filterChange()
{
	var gid = $('#slGroup').val();
	var typetime = $('#typetime').val();
	var fd = $('#slDate').val().split(' / ');
	var user = $('#txtUser').val();
	var limit = $('#lstLimit').val();
	window.location.href = '<?php echo site_url('budget/agency/');?>?gid='+gid+'&type='+typetime+'&usr='+user+'&fd='+fd[0]+'&td='+fd[1]+'&limit='+limit; 
}
$('#slDate').DatePicker({
	format:'Y-m-d',
	date: ['<?php echo $startdate;?>', '<?php echo $enddate;?>'],
	current: '<?php echo date('Y-m-d');?>',
	calendars: 2,
	mode: 'range',
	starts: 1,
	position: 'bottom',
	onChange: function(formated, dates){
		$('#slDate').val(formated);
		$('#slDate').val(formated.join(' / '));
		$('#slDate').DatePickerHide();
	}
});
</script>